package com.example.myproject.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import com.example.myproject.jsontest.compare_performance.JsonObject;
import org.junit.Assert;

import java.util.List;

public class JsonPathTest {
    public static void main(String[] args) {
        String str ="{\"page\":{\"pageSize\":20,\"pageNum\":1},\"searchPropertyDTO\":{\"sortTypeAppEnum\":\"DESC\",\"propertyQueryTypeEnum\":\"ALL\",\"sortFieldAppEnum\":\"LAST_FOLLOW_DATE\"}}";
        JSONObject jsonObject = (JSONObject) JSON.parse(str);
        Object  s2 = (Object)JSONPath.eval(jsonObject,"$.page.pageNum");
        System.out.println("s2:"+s2);
        System.out.println("evalStr:"+JSONPath.eval(str,"$.page.pageNum"));

        boolean flag  = JSONPath.set(jsonObject,"$.page","22");
        System.out.println("flag:"+flag+",content:"+JSON.toJSONString(jsonObject));





        JSONObject data = JSONObject.parseObject(
                "{\"other\":[{\"music\":\"海王\",\"movie\":\"神奇女侠\"}],\"address\":\"中国最美丽的地方\",\"gender\":1,\"mobile\":\"9090980\",\"name\":\"张三\",\"age\":23}");

       // System.out.println(JSONPath.paths(data));
        Object name = JSONPath.eval(data, "$.name");
        System.out.println("name:"+name);


        List<String> movie = (List<String>) JSONPath.eval(data, "$.other.movie");
        System.out.println(movie.contains("神奇女侠"));

    }
}
